<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>约战</title>
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../static/js/jquery.md5.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<%
	String para = request.getParameter("f_pu_id");
	int f_pu_id = 0;
	if(para != null)
		f_pu_id = Integer.valueOf(para);
	String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
	var ___userOperateList = '';
	var ___variables = {
		operateCounts:2,//前N次密码修改记录
		pwd_repeat_desc:'新密码不能与前两次密码一样',//错误描述，自行修改
		pwd_maxlength:16//密码最大长度
	};
	$(function() {
		var f_pu_id = <%=f_pu_id%>;
		$.ajax({
			url: "user_show.do?f_pu_id=" + f_pu_id + '&operateCounts=' + ___variables.operateCounts,
			success:function(data){
				var user = JSON.parse(data);
				___userOperateList = user.pmsUserOperateHistory;
				$("#f_pu_id").val(f_pu_id);
				$("#f_pu_name").val(user.f_pu_name);
				$("#f_pu_realName").val(user.f_pu_realName);
				$("#f_pu_sex").val(user.f_pu_sex);
				$("#f_pu_pwd").val(user.f_pu_pwd);
				$("#f_pu_phone").val(user.f_pu_phone);
				$("#f_pu_mobile").val(user.f_pu_mobile);
				$("#f_pu_email").val(user.f_pu_email);
				$("#f_pu_address").val(user.f_pu_address);
				$("#f_pu_status").val(user.f_pu_status);
			}
		});

		$("#contentForm").validate({
			rules: {
				f_pu_name: {
					required: true,
					minlength: 3,
					maxlength: 50
				},
				f_pu_password: {
					required: false,
					minlength: 8,
					maxlength: ___variables.pwd_maxlength,
					ppd: true,
					ppd_independence : true,
					ppd_repeat_letter: false,
					ppd_sort : true,
				    ppd_repeat:true,
					remote: {
						url: "wordList.do",     //后台处理程序
						type: "post",               //数据发送方式
						dataType: "json",           //接受数据格式
						data: {                     //要传递的数据
							value: function () {
								return $("#f_pu_password").val();
							}
						}
					}
				},
				f_pu_repwd: {
					required: false,
					minlength: 8,
					equalTo: "#f_pu_password",
				},
				email: {
					required: false,
					email: true
				}
			},
			messages: {
				f_pu_name: {
					required: "请输入用户账号",
					minlength: "用户账号不能少于3位",
					maxlength: "用户账号不能超过50位"
				},
				f_pu_password: {
					required: "请输入用户密码",
					minlength: "用户密码不能少于8位",
					maxlength: "用户密码不能超过16位",
					pwd: "用户密码必须为8位以上的 至少为数字、大写字母、小写字母、特殊字符的其中3个组合",
					pwd_independence: "密码不能跟账号类似",
					pwd_repeat_letter: "密码不能是连续多个的字母",
					pwd_sort : "密码不能是键盘排序",
					remote: "密码不能是有意义的单词",
					pwd_repeat:___variables.pwd_repeat_desc
				},
				f_pu_repwd: {
					required: "请输入用户确认密码",
					minlength: "用户确认密码不能少于8位",
					equalTo: "用户密码与确认密码需要相同"
				},
				email: "请输入有效的Email地址"
			},
			
		});


		$.validator.addMethod("ppd_repeat",function(value,element,params){
			var __flag = true;
			var __md5value = $.md5(value);
			console.log(___userOperateList);
			console.log(__md5value);
			if(___userOperateList.length>0){
				for(var i=0;i<___userOperateList.length;i++){
					var __elevalue = ___userOperateList[i].f_pu_pwd;
					if(__md5value == __elevalue){
						__flag = false;
						break;
					}
				}
			}
			return this.optional(element)||(__flag);
		}, ___variables.pwd_repeat_desc);

		$.validator.addMethod("ppd",function(value,element,params){
			var ppd = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,}$/;
			return this.optional(element)||(ppd.test(value));
		}, "用户密码必须为8位以上的 至少为数字、大写字母、小写字母、特殊字符的其中3个组合");
		
		$.validator.addMethod("ppd_independence",function(value,element,params){

			var f_pu_name = $("#f_pu_name").val();
			if(value.indexOf(f_pu_name) > -1||value.indexOf(f_pu_name.toLocaleUpperCase()) > -1||value.indexOf(f_pu_name.toLowerCase()) > -1||(value.toLowerCase()).indexOf(f_pu_name.toLowerCase()) > -1){
				value = false;
			}
			if(value!=false&&similar(f_pu_name,value)){
				value = false;
			}
			return this.optional(element)||(value);
		}, "密码不能跟账号类似");
		$.validator.addMethod("ppd_sort",function(value,element,params){
			var flag = _isKeyBoardContinuousChar(value);
			return this.optional(element)||(flag);
		}, "密码不能是键盘排序");
		$.validator.addMethod("ppd_repeat_letter",function(value,element,params){
			var ppd = /(([0-9a-zA-Z])\1{2,})/;
			return this.optional(element)||(ppd.test(value));
		}, "密码不能是连续多个的字母");
	});
	function similar(strA,strB){
	    var similarChar=[["i","l","L","I","1"],["0","o","O","Q","@"],["Z","z","s","S","2"]];
	    var arrA=strA.split("");
	    var arrB=strB.split("");
	    var defaultNum=0;
	    for(var i=0;i<arrA.length;i++){
	        for(var j=0;j<similarChar.length;j++){
	            if(similarChar[j].indexOf(arrA[i].toLocaleLowerCase())!=-1||similarChar[j].indexOf(arrA[i].toLocaleUpperCase)!=-1){
	                strA=strA.replace(arrA[i],similarChar[j][0]);
	            }    
	        }
	    }
	    for(var i=0;i<arrB.length;i++){
	        for(var j=0;j<similarChar.length;j++){
	            if(similarChar[j].indexOf(arrB[i].toLocaleLowerCase())!=-1||similarChar[j].indexOf(arrB[i].toLocaleUpperCase)!=-1){
	                strB=strB.replace(arrB[i],similarChar[j][0]);
	            }    
	        }
	    }
	   for(var i=0;i<strA.length;i++){
	       if(strB.indexOf((strA.substring(i,strA.length)+strA.substring(0,i)))!=-1){
	           console.log("正叙——"+strA.substring(i,strA.length)+strA.substring(0,i))
	            return true;
	       }
	       if(strB.indexOf((strA.substring(strA.length-i,strA.length)+strA.substring(0,strA.length-i)))!=-1){
	           console.log("倒叙——"+strA.substring(strA.length-i,strA.length)+strA.substring(0,strA.length-i))
	            return true;
	       }
	   }
	   if(strB.indexOf(strA)!=-1){
	       return true;
	   }else{
	       return false;
	   }
	}
	function _submitFm() {
	  if($("#contentForm").validate().form()) {
		  if($("#f_pu_password").val()==""){
			  //$("#f_pu_pwd").val($.md5($("#f_pu_password").val()));
				$("#f_pu_password").val($("#f_pu_pwd").val());
				$("#f_pu_repwd").val($("#f_pu_pwd").val());	  
		  }else{
			  $("#f_pu_pwd").val($.md5($("#f_pu_password").val()));
			  $("#f_pu_password").val($.md5($("#f_pu_password").val()));
			  $("#f_pu_repwd").val($.md5($("#f_pu_repwd").val()));
		  }
		
		app_ajax('user_edit.do', $("#contentForm").serialize(), function(data) {
				if (data.success) {
					$.messager.progress('close');
					$.messager.alert('提示', '修改成功！', 'info', function() {
						parent.$('#dlg').dialog('close');
						parent.gotoSearch($('#easyui-treegrid'));
					});
				} else {
					$.messager.alert('提示', data.result, 'info', function() {
						$.messager.progress('close');
					});
				}
		});
	  }
	}
	
	//判断是否为键盘排序密码
	function _isKeyBoardContinuousChar(str) {
		var c1 = [
            ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+'],
            ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '|'],
            ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"'],
            ['Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?']
        ];
        var c2 = [
            ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '='],
            ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],
            ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\''],
            ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/']
        ];
        str = str.split("");
        //获取坐标位置
        var y = [];
        var x = [];
        for (var c = 0; c < str.length; c++) {
            y[c] = 0;//当做~`键处理
            x[c] = -1;
            for (var i = 0; i < c1.length; i++) {
                for (var j = 0; j < c1[i].length; j++) {
                    if (str[c] == c1[i][j]) {
                        y[c] = i;
                        x[c] = j;
                    }
                }
            }
            if (x[c] != -1) continue;
            for (var i = 0; i < c2.length; i++) {
                for (var j = 0; j < c2[i].length; j++) {
                    if (str[c] == c2[i][j]) {
                        y[c] = i;
                        x[c] = j;
                    }
                }
            }
        }
        //匹配坐标连线
        for (var c = 1; c < str.length - 1; c++) {
            if (y[c - 1] == y[c] && y[c] == y[c + 1]) {
                if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c + 1] + 1 == x[c] && x[c] + 1 == x[c - 1])) {
                	return false;
                }
            } else if (x[c - 1] == x[c] && x[c] == x[c + 1]) {
                if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) {
                	return false;
                }
            }
        }
        return true;
    }
</script>
</head>

<body class="overfwidth">
	<div class="barnavtop">您所在的位置：用户管理 &gt; 用户修改</div>
	<div id="workspace">
		<!--主体 开始-->
		<div id="container">
			<div class="editspace">
				<form id="contentForm" class="cmxform" enctype="multipart/form-data"
					name="formName">
					<legend>用户修改</legend>
					<input type="hidden" id="f_pu_id" name="f_pu_id" value="" />
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right"><span class="red">*</span>用户账号：</td>
									<td width="70%"><input name="f_pu_name" id="f_pu_name"
										style="width: 150px;" value="" class="yl_inp yw_name" /> <span
										id="f_pu_name_tip" class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right"><span class="red">*</span>用户密码：
									</td>
									<td width="70%"><input type="password"
										name="f_pu_password" id="f_pu_password" style="width: 150px;"
										value="" class="yl_inp yw_name" /> <input type="hidden"
										name="f_pu_pwd" id="f_pu_pwd" value="" /></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right"><span class="red">*</span>确认用户密码：</td>
									<td width="70%"><input type="password" name="f_pu_repwd"
										id="f_pu_repwd" style="width: 150px;" value=""
										class="yl_inp yw_name" /></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right"><span class="red">*</span>用户姓名：</td>
									<td width="70%"><input name="f_pu_realName"
										id="f_pu_realName" style="width: 150px;" value=""
										class="yl_inp yw_name" /> <span id="f_pu_realName_tip"
										class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">性别：</td>
									<td width="70%"><select name="f_pu_sex" id="f_pu_sex"
										style="width: 150px;">
											<option value="3">未知</option>
											<option value="1">男</option>
											<option value="0">女</option>
									</select> <span id="f_pu_sex_tip" class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">用户电话：</td>
									<td width="70%"><input name="f_pu_phone" id="f_pu_phone"
										style="width: 150px;" value="" class="yl_inp yw_name" /> <span
										id="f_pu_phone_tip" class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">用户手机：</td>
									<td width="70%"><input name="f_pu_mobile" id="f_pu_mobile"
										style="width: 150px;" value="" class="yl_inp yw_name" /> <span
										id="f_pu_mobile_tip" class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">Email地址：</td>
									<td width="70%"><input name="f_pu_email" id="f_pu_email"
										style="width: 150px;" value="" class="yl_inp yw_name" /> <span
										id="f_pu_email_tip" class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">用户地址：</td>
									<td width="70%"><input name="f_pu_address"
										id="f_pu_address" style="width: 150px;" value=""
										class="yl_inp yw_name" /> <span id="f_pu_address_tip"
										class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">用户状态：</td>
									<td width="70%"><select name="f_pu_status"
										id="f_pu_status" style="width: 150px;">
											<option value="0">未知</option>
											<option value="1">有效</option>
											<option value="2">无效</option>
									</select> <span id="f_pu_status_tip" class="tip"></span></td>
								</tr>
							</table>
						</div>
					</fieldset>
					<input type="hidden" name="stime" value="<%=nonceObj[0]%>"/>
					<input type="hidden" name="sign" value="<%=nonceObj[1]%>"/>
				</form>
			</div>
			<div class="toolbar" style="text-align: center;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
					href="javascript:void(0);" onclick="_submitFm()">保存</a> <a
					href="javascript:void(0);" data-options="iconCls:'icon-cancel'"
					class="easyui-linkbutton"
					onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
			</div>
		</div>
		<!--主体 结束-->
	</div>
</body>
</html>
